package com.zcshou.view;

import android.app.Dialog;
import android.content.Context;

import androidx.annotation.NonNull;

import com.zcshou.gogogo.databinding.PopUpMaxBikeSpeedBinding;

// 继承弹窗
public class PopUpMaxBikeSpeedView extends Dialog {


    public PopUpMaxBikeSpeedView(@NonNull Context context) {
        super(context);
        init();
    }

    public PopUpMaxBikeSpeedView(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    private PopUpMaxBikeSpeedBinding binding;

    private void init(){
        binding = PopUpMaxBikeSpeedBinding.inflate(getLayoutInflater(), null, false);
        setContentView(binding.getRoot());

        binding.btnMaxBikeSpeed.setOnClickListener(v -> {
            setMaxSpeed();
            dismiss();
        });
    }

    public void setOnSpeedSetCallBack(OnSpeedSetCallBack onSpeedSetCallBack) {
        this.onSpeedSetCallBack = onSpeedSetCallBack;
    }

    private OnSpeedSetCallBack onSpeedSetCallBack;

    public void setMaxSpeed() {
        double maxSpeedDouble = 10.0;
        try {
            maxSpeedDouble = Double.parseDouble(binding.etMaxBikeSpeed.getText().toString());
        } catch (Exception e) {
            maxSpeedDouble = 10.0;
        }
        if (maxSpeedDouble < 10.0) {
            maxSpeedDouble = 10.0;
        }
        onSpeedSetCallBack.onSpeedSet(maxSpeedDouble);
    }
}
